<template>
  <page-header-wrapper :title="false" >
    <a-card>
      <div class="table-page-search-wrapper">
        <a-form layout="inline">
          <a-row :gutter="48">
            <a-col :md="6" :sm="24">
              <a-form-item label="筛选">
                <a-input v-model="queryParam.queryCondition" allow-clear placeholder="请输入" />
              </a-form-item>
            </a-col>
            <a-col :md="!advanced && 8 || 24" :sm="24">
              <span class="table-page-search-submitButtons" :style="advanced && { float: 'right', overflow: 'hidden' } || {} ">
                <a-button type="primary" @click="handleSearch()">查询</a-button>
                <a-button style="margin-left: 8px" @click="() => queryParam = {}">重置</a-button>
                <!-- <a @click="toggleAdvanced" style="margin-left: 8px">
                  {{ advanced ? '收起' : '展开' }}
                  <a-icon :type="advanced ? 'up' : 'down'"/>
                </a> -->
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <a-table
        ref="table"
        size="default"
        rowKey="key"
        :pagination="pagination"
        @change="handleTableChange"
        :columns="columns"
        :data-source="loadData"
      >
        <span slot="action" slot-scope="text, record">
          <template>
            <a-tag color="#428bca" @click="handle(record)">进入</a-tag>       
          </template>
        </span>
      </a-table>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import { getStoreListUsingPOST } from '@/api/api/mendianguanli.ts'
export default {
  name: 'CashierPaymentRecordIndex',
  data () {
    return {
      mdl: null,
      visible: false,
      value:'',
      confirmLoading:false,
      // 高级搜索 展开/关闭
      advanced: false,
        // 查询参数
      pagination:{
        total: 0
      },
      queryParam: {
        pageNo:1,
        pageSize:10,
        queryCondition:'',
        status:''
      },
      // 表头
      columns: [
        {
          title: '店面名称',
          dataIndex: 'storeName'
        },
        {
          title: '操作',
          dataIndex: 'action',
          width: '220px',
          scopedSlots: { customRender: 'action' }
        }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: [],
    }
  },
  mounted () {
    this.handleSearch(this.queryParam)
  },
  methods: {
    handleSearch (params) {
      getStoreListUsingPOST(params).then((res) => {
        this.loadData = res.data.list
        this.queryParam.pageNo = this.pagination.current
        this.pagination = { ...this.pagination, total: Number(res.data.total) }
      })
      .catch((error) => {
        this.$message.error(((error.response || {}).data || {}).msg || '请求出现错误')
      })
    },
    handleTableChange(pagination, filters, sorter) {
      const pager = { ...this.pagination }
      pager.current = pagination.current
 pager.pageSize = pagination.pageSize
      this.pagination = pager
      this.handleSearch({
        sortField: sorter.field,
        sortOrder: sorter.order,
        ...filters,
        pageNo:pagination.current,
        pageSize:pagination.pageSize,
        queryCondition:this.queryParam.queryCondition,
        status:this.queryParam.status,
        date:this.queryParam.date
      })
    },
    handle(record){
      this.$router.push({ path: `/cashier/paymentRecord/${record?.id}` })
    },
    handleBoth (record) {
      this.mdl = { ...record }
      this.visible = true
    },
    handleOk () {
      this.visible = false
      this.confirmLoading = true
      setTimeout(() => {
        this.confirmLoading = false
      }, 1000)
      this.$message.success('操作成功')
    },
    handleCancel () {
      this.visible = false
      const form = this.$refs.createModal.form
      form.resetFields() // 清理表单数据（可不做）
    },
  }
}
</script>